package de.andreavicentini.teatralia.pages;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class ObjectListModel<T extends Comparable<T>> implements Iterable<T>{
	
	private final List<T> list = new ArrayList<T>();
	private boolean sorted = false;
	
	public ObjectListModel() {
	}
	
	public ObjectListModel<T> add(T object) {
		this.list.add(object);
		return this;
	}
	
	public Iterator<T> iterator() {
		if (! this.sorted) Collections.sort(list);
		return this.list.iterator();
	}
}
